<!--
tabs-item: lab: tab显示字段; badge: 标记
-->
<template>
  <ul class="m-tabs">
    <li
      v-for="(item, index) in tabsArr"
      :key="'k' + index"
      class="tabs-item"
      :class="{ active: index === tabsActiveIndex }"
      @click.stop="tabsHandle(index)"
    >
      <span class="item-font" :class="{ 'dis-btn': item.disabled }">
        <el-badge :value="item.badge" :max="99">
          {{ item.lab }}
        </el-badge>
      </span>
      <!-- <span class="item-border" /> -->
    </li>
  </ul>
</template>
<script>
export default {
  name: 'CustomTabs',
  props: {
    activeIndex: {
      type: Number,
      default: 0,
    },
    tabsArr: {
      type: Array,
      required: true,
    },
  },
  data() {
    return {
      tabsActiveIndex: null,
    };
  },
  watch: {
    activeIndex: {
      immediate: true,
      handler(val) {
        this.tabsActiveIndex = val;
      },
    },
  },
  methods: {
    tabsHandle(index) {
      if (this.tabsArr[index].disabled) {
        return;
      }
      this.tabsActiveIndex = index;
      this.$emit('returnIndex', index);
    },
  },
};
</script>
<style lang="less" scope>
@import '../../assets/m-var.less';

.m-tabs {
  padding-left: 0;
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  .tabs-item {
    list-style: none;
    padding: 0 26px;
    height: 54px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-sizing: border-box;
    border-bottom: 3px solid #ffffff;
    .item-font {
      font-weight: @boldFontWeight;
      color: @titleTextColor;
    }

    .item-border {
      display: none;
      height: 2px;
      width: 20px;
      border-radius: 2px;
      background-color: transparent;
    }
    &.active {
      font-size: 16px;
      font-weight: 500;
      box-sizing: border-box;
      border-bottom: 3px solid @dominantHue;
      .item-font {
        font-size: 16px;
        color: @dominantHue;
      }
    }
  }
  .dis-btn {
    color: #c2c2c2 !important;
  }
  .el-badge__content.is-fixed {
    top: -5px;
    right: 7px;
  }
}
</style>
